const Joi = require('@hapi/joi')

const schemeConfig = {
  allowUnknown: true,
  abortEarly: true
}

const base = Joi.object({
  userName: Joi.string()
    .min(0)
    .max(10)
    .required(),
  passWord: Joi.string().required()
})

const extend = base.keys({
  add: Joi.number()
    .valid(0, 1)
    .allow(3)
    .default(null)
})

const schema = extend

let validateFn = validateDate => {
  let result = schema.validate(validateDate, schemeConfig)
  console.log(result)
}

let input = { userName: 'userName91', passWord: 'password', add: 3 }

validateFn(input)
